package com.wx.app.spacewhisper.utils.result;

/**
 * 结果类封装类
 * 使用方法如:UserInfo userInfo = userInfoService.selectById(id);
 * return RetResponse.makeOKRsp(userInfo);
 * 控制器层需要统一返回结果
 */
public class RetResponse {

    private final static String SUCCESS = "success";

    public static <T> RetResult<T> makeOKRsp() {
        return new RetResult<T>().setCode(RetCode.SUCCESS).setMsg(SUCCESS);
    }

    public static <T> RetResult<T> makeOKRsp(T data) {
        return new RetResult<T>().setCode(RetCode.SUCCESS).setMsg(SUCCESS).setData(data);
    }

    public static <T> RetResult<T> makeOKRsp(MessageEnum message) {
        return new RetResult<T>().setCode(RetCode.SUCCESS).setMsg(message.getMessage());
    }

    public static <T> RetResult<T> makeOKRsp(MessageEnum message, T data) {
        return new RetResult<T>().setCode(RetCode.SUCCESS).setMsg(message.getMessage()).setData(data);
    }

    public static <T> RetResult<T> makeErrRsp(String message) {
        return new RetResult<T>().setCode(RetCode.FAIL).setMsg(message);
    }

    public static <T> RetResult<T> makeErrRsp(MessageEnum message) {
        return new RetResult<T>().setCode(RetCode.FAIL).setMsg(message.getMessage());
    }

    public static <T> RetResult<T> makeRsp(int code, String msg) {
        return new RetResult<T>().setCode(code).setMsg(msg);
    }

    public static <T> RetResult<T> makeRsp(int code, MessageEnum msg) {
        return new RetResult<T>().setCode(code).setMsg(msg.getMessage());
    }

    public static <T> RetResult<T> makeRsp(int code, String msg, T data) {
        return new RetResult<T>().setCode(code).setMsg(msg).setData(data);
    }

    public static <T> RetResult<T> makeRsp(int code, MessageEnum msg, T data) {
        return new RetResult<T>().setCode(code).setMsg(msg.getMessage()).setData(data);
    }
}